package com.ai.platform.business.service.impl;

import com.ai.platform.business.entity.BusiReport;
import com.ai.platform.business.mapper.BusiReportMapper;
import com.ai.platform.business.service.IBusiReportService;
import com.ai.platform.core.exception.BusinessException;
import com.ai.platform.model.dto.Input;
import com.ai.platform.model.dto.Output;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yeyingsheng
 * @since 2018-06-01
 */
@Service
public class BusiReportServiceImpl extends ServiceImpl<BusiReportMapper, BusiReport> implements IBusiReportService {

    @Override
    public void reportList(Input input, Output output) throws BusinessException {
        //每页显示条数
        int limit =Integer.parseInt(input.getValue("limit"));
        //当前页
        int pageNow = Integer.valueOf(input.getValue("page"));
        EntityWrapper<BusiReport> wrapper=new EntityWrapper<>();
        Page<BusiReport> page = new Page(pageNow,limit);
        page.setTotal(this.selectCount(wrapper));
        page=this.selectPage(page,wrapper);
        output.setCount(page.getTotal());
        List<BusiReport> list=page.getRecords();
        output.setData(list);
    }

    @Override
    public void reportListById(Input input, Output output) throws BusinessException {
        String reportId=input.getValue("reportId");
        BusiReport busiReport=this.selectOne(new EntityWrapper<BusiReport>().eq("report_id",reportId));
        if(null!=busiReport){
            //获取查询SQL
            String sqlText=busiReport.getReportSql();
            //执行SQL查询

        }
    }
}
